<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
    //创建一个name变量
    var name="全局";//此时name属于全局变量，即window.name

    //创建一个fun()函数
    function fun()
    {
        console.log(this.name);
    }

    //创建两个对象
    var obj =
    {
        name:"孙悟空",
        sayName:fun
    };

    var obj2 =
    {
        name:"沙和尚",
        sayName:fun
    };
    //
    fun();
    obj.sayName();
    obj2.sayName();

    //我们希望调用obj.sayName()时可以输出obj的名字
    </script>
</head>
<body>
    
</body>
</html>